package iamutkarshtiwari.github.io.ananas.editimage.fragment.paint;

import iamutkarshtiwari.github.io.ananas.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Slider;
import ohos.agp.utils.TextAlignment;
import ohos.agp.window.dialog.CommonDialog;
import ohos.agp.window.service.Window;
import ohos.app.Context;

public class EraserConfigDialog extends CommonDialog implements Slider.ValueChangedListener {

    private Properties mProperties;

    /**
     * 属性改变接口
     */
    public interface Properties {
        void onBrushSizeChanged(int brushSize);
    }

    /**
     * 构造
     *
     * @param context Context对象
     */
    public EraserConfigDialog(Context context) {
        super(context);
        Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_fragment_eraser_config, null, false);
        setContentCustomComponent(component);
        setCornerRadius(0);
        component.setLayoutConfig(new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, 300));

        Window window = getWindow();
        window.setLayoutAlignment(TextAlignment.BOTTOM);

        Slider eraserSlider = (Slider) component.findComponentById(ResourceTable.Id_sbSize);
        eraserSlider.setValueChangedListener(this);

        setDialogListener(() -> {
            hide();
            return true;
        });
    }

    /**
     * 设置属性改变监听
     *
     * @param properties
     */
    public void setPropertiesChangeListener(Properties properties) {
        mProperties = properties;
    }

    @Override
    public void onProgressUpdated(Slider slider, int i, boolean b) {
        int id = slider.getId();
        if (id == ResourceTable.Id_sbSize) {
            if (mProperties != null) {
                mProperties.onBrushSizeChanged(i);
            }
        }
    }

    @Override
    public void onTouchStart(Slider slider) {

    }

    @Override
    public void onTouchEnd(Slider slider) {

    }
}
